<?php

namespace iBrand\Shop\Core\Models;

use Illuminate\Database\Eloquent\Model;

class UserShop extends Model
{

    protected $guarded = ['id'];
    protected $appends = ['shop_name'];

    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);

        $prefix = config('ibrand.app.database.prefix', 'ibrand_');

        $this->setTable('o2o_user_shop');
    }

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function shop()
    {
        return $this->belongsTo(Shop::class, 'shop_id')->withDefault();
    }

    public function getShopNameAttribute()
    {
        if ($this->shop) {
            return $this->shop->name;
        }
        return '';
    }

}

